<?php

/**
 * This is the model class for table "cs_users".
 *
 * The followings are the available columns in table 'cs_users':
 * @property integer $uid
 * @property string $username
 * @property string $password
 * @property string $salt
 * @property integer $balance
 * @property string $email
 * @property string $fullname
 * @property string $add
 * @property string $city
 * @property string $state
 * @property string $country
 * @property string $register_time
 * @property string $activation
 * @property string $last_login_time
 * @property string $last_update_time
 */
class User extends CActiveRecord
{
    
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Users the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'cs_users';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('username, password', 'required'),
			array('balance', 'numerical', 'integerOnly'=>true),
			array('username, email, fullname, add, city, state, country', 'length', 'max'=>45),
			array('password, activation', 'length', 'max'=>100),
			array('salt', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('uid, username, password, salt, balance, email, fullname, add, city, state, country, register_time, activation, last_login_time, last_update_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'uid' => 'Uid',
			'username' => 'Username',
			'password' => 'Password',
			'salt' => 'Salt',
			'balance' => 'Balance',
			'email' => 'Email',
			'fullname' => 'Fullname',
			'add' => 'Add',
			'city' => 'City',
			'state' => 'State',
			'country' => 'Country',
			'register_time' => 'Register Time',
			'activation' => 'Activation',
			'last_login_time' => 'Last Login Time',
			'last_update_time' => 'Last Update Time',
		);
	}



    public function scopes() {
        return array(
            'notsafe' => array(
                'select' => 'uid, username, password,salt
                 last_login_time,last_update_time ',
            ),
        );
    }

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('uid',$this->uid);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('salt',$this->salt,true);
		$criteria->compare('balance',$this->balance);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('fullname',$this->fullname,true);
		$criteria->compare('add',$this->add,true);
		$criteria->compare('city',$this->city,true);
		$criteria->compare('state',$this->state,true);
		$criteria->compare('country',$this->country,true);
		$criteria->compare('register_time',$this->register_time,true);
		$criteria->compare('activation',$this->activation,true);
		$criteria->compare('last_login_time',$this->last_login_time,true);
		$criteria->compare('last_update_time',$this->last_update_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}